﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

public partial class Default : Telerik.Web.UI.RadAjaxPage 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void btnEnter_Click(object sender, EventArgs e)
    {
        try
        {
           GPSTrackingServerDB.Entities.Admin adminEntity = GPSTrackingServerDB.Data.DataRepository.AdminProvider.GetByAdminUsername(txtUsername.Text);

           if (adminEntity != null)
           {
               if (adminEntity.IsActive)
               {
                   if (adminEntity.Password == txtPassword.Text)
                   {
                       System.Web.Security.FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
                   }
                   else
                   {
                       ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ShowInfo", "show_Info('" + "Usuario o contraseña son incorrectas" + "','Administrador error ...');", true);
                   }
               }
               else
               {
                   ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ShowInfo", "show_Info('" + "Administrador esta desactivado" + "','Administrador error ...');", true);
               }
           }
           else
           {
               ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ShowInfo", "show_Info('" + "Usuario o contraseña son incorrectas" + "','Administrador error ...');", true);
           }
        }
        catch (Exception ex)
        {
            GPSTrackingLogCustom.WebsiteLog.Error(ex.Message);
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ShowErrorCatch", "show_Error('" + ex.Message + "','Administrador error ...');", true);
        }
    }
}
